#!/bin/bash

#=======================================================================
# git-mnff
# File ID: b72aedb2-f178-11e4-a17f-000df06acc56
#
# Perform Git merges without fast-forwarding. Useful for visualising 
# related commits.
#
# Syntax:
#
#   git mnff BRANCHNAME
#   git mnff BRANCHNAME STARTREVISION_OF_BRANCH
#
# Author: Øyvind A. Holm <sunny@sunbase.org>
# License: GNU General Public License version 2 or later.
#=======================================================================

git wait-until-clean -u

branch=$1
if test -n "$2"; then
    reset="$2"
    git branch $branch &&
    git reset --hard $reset
fi

if test $(git log --format='%h' ..$branch | wc -l) -lt 2; then
    # There is only one commit, use fast-forward if possible
    git merge $branch
else
    # There is more than 1 commit, use --no-ff
    git merge --no-ff $branch
fi

git branch -d $branch
